package inits

import (
	"github.com/casbin/casbin/v2"
	gormadapter "github.com/casbin/gorm-adapter/v3"
	"go_pure_admin_api/global"
)

func CasbinInit() {
	//dsn := viper.GetString("mysql.dsn")
	//a, err := gormadapter.NewAdapter("mysql", dsn, true)
	a, err := gormadapter.NewAdapterByDB(global.DB)
	if err != nil {
		global.Logger.Panic("casbin连接数据库失败", err)
	}
	Ecasbin, err := casbin.NewEnforcer("config/casbin.conf", a)
	if err != nil {
		global.Logger.Panic("casbin加载配置失败", err)
	}
	global.Casbin = Ecasbin
	global.Logger.Info("casbin初始化成功")
}
